package 强密码检验器;

/**
 * @Program:IntelliJ IDEA
 * @description:
 * @author:香蕉你个啵娜娜 l.h-p@qq.com
 * @create:2023-01-19 22:18
 **/

public class Solution {
    public boolean strongPasswordChecker(String password){
        if (password.length() < 8){
            return false;
        }
        boolean[] v = new boolean[127];
        "!@#$^&*()_+".chars().forEach(i -> v[i] = true);
        int ans = 0;
        for (int i = 0; i < password.length(); i++) {
            char c = password.charAt(i);
            if (c >= '0' && c <= '9') {
                ans |= 1 <<2;
            }
            if (c >= 'a' && c <= 'z') {
                ans |= 1<<0;
            }
            if (c >= 'A' && c <= 'Z') {
                ans |= 1 <<1;
            }
            if (v[c]){
                ans |= 1<<3;
            }
            if (i > 0 && password.charAt(i - 1) == c){
                return false;
            }
        }
        return ans == ((1 << 4) - 1);
    }
}
